package entity;

import java.sql.SQLException;

import utils.SaveManager;
import dao.DbClass;

public class Pokemon {

	public static final int ID = 0;
	public static final int INITIAL_LVL = 1;
	public static final int MIN_EXP = 0;
	public static final int MAX_EXP = 100;
	SaveManager svManager = new SaveManager();
	
	private int id_banco;
	private int id;	
	private String name;	
	private int attack;
	private int defence;
	private int speed;
	private int expGain;
	private int currentHp;
	private int hp;
	private String type1;
	private String type2;
	private String abilitie1;
	private String abilitie2;
	private int rarity;
	
	//atributos no save.txt
	private int level;
	private int experience;
	private char activated;
	
	public Pokemon() {		
		this(ID, INITIAL_LVL, MIN_EXP);
	}

	public Pokemon(int id) {
		this(id, INITIAL_LVL, MIN_EXP);
		Pokemon pok = null;
		try {
			pok = svManager.getPokemonAtributes(id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		this.id = id;	
		this.name = pok.getName();	
		this.attack = pok.getAttack();
		this.defence = pok.getDefence();
		this.speed = pok.getSpeed();
		this.expGain = pok.getExpGain();
		this.currentHp = pok.getCurrentHp();
		this.hp = pok.getHp();
		this.type1 = pok.getType1();
		this.type2 = pok.getType2();
		this.abilitie1 = pok.getAbilitie1();
		this.abilitie2 = pok.getAbilitie2();
		this.rarity = pok.getRarity();
	}
	
	public Pokemon(int id, int level, int experience) {
		setId(id);
		setLevel(level);
		setExperience(experience);
	}

//	public Pokemon(int id, int level, int experience, int current_hp) {
//		setId(id);
//		setLevel(level);
//		setExperience(experience);
//		setCurrentHp(current_hp);
//	}

	public Pokemon(int id, String name, int hp, int attack, int defence, int speed, int expGain, String type1, String type2,
			String abilitie1,String abilitie2, int rarity){
		setCurrentHp(hp);
		setId(id);
		setName(name);
		setHp(hp);
		setAttack(attack);
		setDefence(defence);
		setSpeed(speed);
		setExpGain(expGain);
		setType1(type1);
		setType2(type2);
		setAbilitie1(abilitie1);
		setAbilitie2(abilitie2);
		setRarity(rarity);
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getCurrentHp() {
		return currentHp;
	}

	public void setCurrentHp(int currentHp) {
		this.currentHp = currentHp;
	}

	public int getHp() {
		return hp;
	}

	public void setHp(int hp) {
		this.hp = hp;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getExperience() {
		return experience;
	}

	public void setExperience(int experience) {
		this.experience = experience;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAttack() {
		return attack;
	}

	public void setAttack(int attack) {
		this.attack = attack;
	}

	public int getDefence() {
		return defence;
	}

	public void setDefence(int defence) {
		this.defence = defence;
	}

	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}
	
	public int getExpGain() {
		return expGain;
	}

	public void setExpGain(int expGain) {
		this.expGain = expGain;
	}

	public String getType1() {
		return type1;
	}

	public void setType1(String type1) {
		this.type1 = type1;
	}

	public String getType2() {
		return type2;
	}

	public void setType2(String type2) {
		this.type2 = type2;
	}

	public String getAbilitie1() {
		return abilitie1;
	}

	public void setAbilitie1(String abilitie1) {
		this.abilitie1 = abilitie1;
	}

	public String getAbilitie2() {
		return abilitie2;
	}

	public void setAbilitie2(String abilitie2) {
		this.abilitie2 = abilitie2;
	}
	public int getRarity() {
		return rarity;
	}

	public void setRarity(int rarity) {
		this.rarity = rarity;
	}

	public void adicionarExperiencia(int experience) {
		int expAdicional;
		System.out.println("Level anterior - " + getLevel()
				+ " Experiencia Anterior - " + getExperience());
		if (getExperience() + experience > MAX_EXP) {
			expAdicional = getExperience() + experience - MAX_EXP;
			setLevel(getLevel() + 1);
			setExperience(expAdicional);
		} else {
			setExperience(getExperience() + experience);
		}
		System.out.println("Level Atual - " + getLevel()
				+ " Experiencia Atual - " + getExperience());
	}

	/**
	 * @return the activated
	 */
	public char getActivated() {
		return activated;
	}

	/**
	 * @param activated the activated to set
	 */
	public void setActivated(char activated) {
		this.activated = activated;
	}

	/**
	 * @return the id_banco
	 */
	public int getId_banco() {
		return id_banco;
	}

	/**
	 * @param id_banco the id_banco to set
	 */
	public void setId_banco(int id_banco) {
		this.id_banco = id_banco;
	}
}
